package com.proscenic.ops.common.config.mp;

import com.proscenic.ops.mp.handle.SubscribeHandler;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.api.WxMpMessageRouter;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * 路由配置
 * @version 1.0
 * created by chenxin on 2021/11/3 12:03
 */
@Configuration
public class RouterConfig {
    @Resource
    private WxMpService wxMpService;
    @Resource
    private SubscribeHandler subscribeHandler;

    @Bean(name = "mpRouter")
    @PostConstruct
    public WxMpMessageRouter router(){
        WxMpMessageRouter router = new WxMpMessageRouter(wxMpService);

        //关注事件
        router.rule().async(false).msgType(WxConsts.XmlMsgType.EVENT).event(WxConsts.EventType.SUBSCRIBE).handler(subscribeHandler).end();

        return router;
    }
}
